package com.dennytech.tac.ui.adapter;

import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.dennytech.tac.base.BasicAdapter;
import com.dennytech.tac.model.Attraction;
import com.dennytech.tac.widget.AttractionListItem;
import com.dennytech.tac.R;

public class AttractionListAdapter extends BasicAdapter {

	private List<Attraction> data;

	public void setData(List<Attraction> d) {
		this.data = d;
		notifyDataSetChanged();
	}

	public void clearData() {
		if (data != null) {
			data.clear();
		}
		notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return data == null ? 0 : data.size();
	}

	@Override
	public Attraction getItem(int position) {
		return data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		if (view == null) {
			view = LayoutInflater.from(parent.getContext()).inflate(
					R.layout.tourist_attraction_list_item, parent, false);
		}

		Attraction ta = getItem(position);
		((AttractionListItem) view).setAttraction(ta);
		return view;
	}
}